// JavaScript Document
function addTimeOptionDivCss()
{
	var detailListDiv=$(".timeLineOption .detailList div");
	$.each(detailListDiv,function(i,items){
		if(i==detailListDiv.length-1){
			$(items).addClass("lastListOption");
		}else{
			$(items).addClass("listOption");
		}
	});
}
/*初始化我的佣金*/
function initMyCommission(){
	var contentURl1=jsonserver+"home_CountCommissionMonth.do";
	var contentParamsStr1="natureid="+fid+"&Ukey="+ukey;
	$.ajax({
			url:contentURl1+"?callback=?",//获取JSON
			data:contentParamsStr1,
			dataType:"jsonp",
			success:function(json){
				//alert(1);
				if(json[0].result==1){	
					$("#curMonth").text(json[1].ONTIME.substring(5,7)*1+"月");
					$("#showMoney").text(json[1].TOTAL);
				}
			},
			error:function(){
				alert("报错了");
			}
			
		})
}
/*初始化时间轴*/
function initContent(){
	//初始化我的佣金
	initMyCommission();
	var contentURl2=jsonserver+"home_timeOnline.do";
	var contentParamsStr2="natureid="+fid+"&Ukey="+ukey;
	$.ajax({
			url:contentURl2+"?callback=?",//获取JSON
			data:contentParamsStr2,
			dataType:"jsonp",
			success:function(json){
				
				if(json[0].result==1){	
					$(".timeLine").children().remove();
					var resultArray=json[1];
					//alert(resultArray.length);
					$.each(resultArray,function(i,items){
						
						var optionDiv=$("<div/>").addClass("timeLineOption");
						if(i==0){
							//alert(items.PAISONG);
							var todayStr='<table width="100%">'+
											'<tr>'+
												'<td class="listLogo"><img src="images/index/index_time1.png"/></td>'+
												'<td>'+
												 '<div class="detailList">'+
													  '<div class="listTitle">'+getDayText(i)+'&nbsp; &nbsp;&nbsp;<span>'+items.DTD+'</span></div>'+
													  '<div> '+
														'<span style=" float:left">您今天没有办理推荐业务信息</span>'+
														'<div class="recBtn" style="height: 50px; line-height:50px; border:none;font-size:22px;" onClick="requestRec()">点这里推荐一下!</div>'+
													  '</div>'+
													  '<div class="detailOption"><img src="images/index/index_procing.png"/><span style="margin-top:250px;">正在办理&nbsp;<label id="BANLI">'+items.BANLI+'</label>&nbsp;单</span><img src="images/wo_list_jiantou.png"/> </div>'+
													  '<div class="detailOption"><img src="images/index/index_sending.png"/><span>正在派送&nbsp;<label id="PAISONG">'+items.PAISONG+'</label>&nbsp;单</span><img src="images/wo_list_jiantou.png"/></div>'+
													  '<div class="detailOption"><img src="images/index/index_recresult.png"/><span>推荐结果&nbsp;<label id="JIEGUO">'+items.JIEGUO+'</label>&nbsp;条</span><img src="images/wo_list_jiantou.png"/></div>'+
													  '<div class="detailOption"><img src="images/index/index_back.png"/><span>返佣消息&nbsp;<label id="FANYONG">'+items.FANYONG+'</label>&nbsp;条</span><img src="images/wo_list_jiantou.png"/></div>'+
												  '</div>'+
												'</td>'+
											'</tr>'+
										'</table>';
							   optionDiv.append(todayStr);	
						}else if(i==resultArray.length-1){
							var todayStr='<table width="100%">'+
											'<tr>'+
												'<td class="listLogo"><img src="images/index/index_time2.png"/></td>'+
												'<td>'+
												 '<div class="detailList">'+
													  '<div class="listTitle"><span style=" font-size:42px;">'+items.DTD+'开始</span></div>'+
													  '<div class="detailOption"><img src="images/index/index_procing.png"/><span style="margin-top:250px;">正在办理&nbsp;<label id="BANLI">'+items.BANLI+'</label>&nbsp;单</span><img src="images/wo_list_jiantou.png"/> </div>'+
													  '<div class="detailOption"><img src="images/index/index_sending.png"/><span>正在派送&nbsp;<label id="PAISONG">'+items.PAISONG+'</label>&nbsp;单</span><img src="images/wo_list_jiantou.png"/></div>'+
													  '<div class="detailOption"><img src="images/index/index_recresult.png"/><span>推荐结果&nbsp;<label id="JIEGUO">'+items.JIEGUO+'</label>&nbsp;条</span><img src="images/wo_list_jiantou.png"/></div>'+
													  '<div class="detailOption"><img src="images/index/index_back.png"/><span>返佣消息&nbsp;<label id="FANYONG">'+items.FANYONG+'</label>&nbsp;条</span><img src="images/wo_list_jiantou.png"/></div>'+
												  '</div>'+
												'</td>'+
											'</tr>'+
										'</table>';
							optionDiv.append(todayStr);	
							
						}else{
							var todayStr='<table width="100%">'+
											'<tr>'+
												'<td class="listLogo"><img src="images/index/index_time2.png"/></td>'+
												'<td>'+
												 '<div class="detailList">'+
													  '<div class="listTitle">'+getDayText(i)+'&nbsp; &nbsp;&nbsp;<span>'+items.DTD+'</span></div>'+
													  '<div class="detailOption"><img src="images/index/index_procing.png"/><span style="margin-top:250px;">正在办理&nbsp;<label id="BANLI">'+items.BANLI+'</label>&nbsp;单</span><img src="images/wo_list_jiantou.png"/> </div>'+
													  '<div class="detailOption"><img src="images/index/index_sending.png"/><span>正在派送&nbsp;<label id="PAISONG">'+items.PAISONG+'</label>&nbsp;单</span><img src="images/wo_list_jiantou.png"/></div>'+
													  '<div class="detailOption"><img src="images/index/index_recresult.png"/><span>推荐结果&nbsp;<label id="JIEGUO">'+items.JIEGUO+'</label>&nbsp;条</span><img src="images/wo_list_jiantou.png"/></div>'+
													  '<div class="detailOption"><img src="images/index/index_back.png"/><span>返佣消息&nbsp;<label id="FANYONG">'+items.FANYONG+'</label>&nbsp;条</span><img src="images/wo_list_jiantou.png"/></div>'+
												  '</div>'+
												'</td>'+
											'</tr>'+
										'</table>';
							optionDiv.append(todayStr);	
						}
						optionDiv.appendTo($(".timeLine"));	
					});
					addTimeOptionDivCss();
				}
			},
			error:function(){
				alert("报错了");
			}
			
		})

	

}
function initMsg(){
	//初始化消息个数
	$.ajax({
			url:jsonserver+"msg_unreadMessageNum.do?callback=?",//获取JSON
			data:"MSG_NATURE_FID="+fid,
			dataType:"jsonp",
			success:function(json)
			{
				var resultCode=json[0].result;
				if(resultCode==1){
					$("#msgCount").text(json[1].unreadMessageNum);
					$("#msgDetail").text(json[1].unreadMessageNum);
				}
			},
			error:function(){
				alert("出错了!");
			}
			
		});	
	//初始化消息列表
	initMsgList();
		
}
function initMsgList(){
	$.ajax({
			url:jsonserver+"msg_getMsgDayList.do?callback=?",//获取JSON
			data:"MSG_NATURE_FID="+fid+"&pageSize=10&MSG_IS_READED=0&setR=0&ukey="+ukey,
			dataType:"jsonp",
			success:function(json)
			{
				$("#msgList .menuOption").children().remove();
				var resultCode=json[0].result;
				if(resultCode==1){
					var datas=json[1].data;
					//alert(datas.length);
					var optionDiv="";
					$.each(datas,function(i,items){
						//alert(1);
						
						optionDiv+='<div style="font-size:28px;" onClick="requestDingxq(\''+items.MSG_ORDER_FID+'\')"><span style="margin-left:5%;">'+items.CUI_NAME+'</span><span style="margin-left:20px; font-size:22px;">'+items.CUI_CONTACTTEL+'</span><span style="margin-left:20px; font-size:20px; color:#ccc;">'+items.MSG_TYPE_NAME+'</span><img src="images/wo_list_jiantou.png" style=" float:right; margin-top:31px; margin-right:10%;"/></div>';
					});
					//alert(optionDiv);
					$("#messageDiv .menuOption").html(optionDiv);
					
				}
			},
			error:function(){
				alert("出错了!");
			}
			
		});	
}
function resize(){

	setTimeout(function(){
		loaded();
	},200);
}
function getDayText(i){
	var t="";
	switch(i){
		case 0:
		t="今天";
		break;
		case 1:
		t="昨天";
		break;
		case 2:
		t="一周内";
		break;
		case 3:
		t="一个月内";
		break;
		case 4:
		t="三个月内";
		break;
		case 5:
		t="历史";
		break;
	}
	return "<span style='font-size:42px;'>"+t+"</span>";
}
/*点击向左或者向右滑动*/
function showMenuOrMessage(fromDivId){
	//获取窗口宽度
	shotDivWidth=$("#"+fromDivId).width();
	//判断是左是右
	if(fromDivId=='menuDiv'){
		shotDivWidth=-shotDivWidth;
	}
	//开始滑动
	hscroll.scrollTo(shotDivWidth,0,500,true);
	hscroll.refresh();
}
/*滑动回主页*/
function returnHome(fromDivId){
	var divWidth=$("#"+fromDivId).width();
	if(fromDivId=='messageDiv'){
		divWidth=-divWidth;
	}
	hscroll.scrollTo(divWidth,0,500,true);
	hscroll.refresh();
}
function requestMsgDetail(){
	window.location.href="message.html?MSG_NATURE_FID="+fid+"&ukey="+ukey;
}
function requestCommission(){
	window.location.href="commission.html?RECOM_NATURE_FID="+fid;
}
function requestRec(){
	
	
	window.location.href="businessRecommend.html";
}
function requestUserinfo(){
	var newFlag=$.cookie("newuser");
	//var newFlag="isNull";
	window.location.href=newFlag=="isNull"?"userInfo.html":"userInfoAdd.html?sign=1";
}
function requestDingxq(msgId){
	window.location.href="dingdanxq.html?OI_ID="+msgId;
}
function requestDetailQuery(){
	window.location.href="detailQuery.html";
}

